#ifndef OPERATELOGMODEL_H
#define OPERATELOGMODEL_H

#include <QAbstractListModel>
#include <QObject>

#define OPERATE_LOG(strlog)  OperateLogModel::getInstance()->addData(strlog);

class OperateLogModel : public QAbstractListModel
{
    Q_OBJECT
public:
    enum OperateLogRoles {
        TimeRole= Qt::UserRole + 1,
        LogRole
    };
    explicit OperateLogModel(QObject *parent = nullptr);
    static OperateLogModel * getInstance();
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;
    void addData(QString strlog);
private:
    struct OperateLogInfo{
        QString strTime;
        QString strlog;
    };
    static OperateLogModel *m_pInstance;
    QVector<OperateLogInfo> m_data;
};

#endif // OPERATELOGMODEL_H
